
package com.liuym.login.aspect;


import com.liuym.common.constants.GradeResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * Title: 全局异常处理切面
 * 处理Controller层RuntimeException异常
 *
 * @author liuym
 */

@ControllerAdvice   // 控制器增强
@ResponseBody
public class ExceptionAspect {


    private static Logger logger = LoggerFactory.getLogger(ExceptionAspect.class);

    public static int num = 0;

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(RuntimeException.class)
    public GradeResponse handleException(RuntimeException e) {
        logger.error("Internal Server Error...", e);
        return GradeResponse.internalServerError();
    }
}
